package org.NooLab.randomgraph.components;

import java.util.ArrayList;

import org.NooLab.structures.randomgraph.RichEntityPositions;

 


/**
 * 
 * 
 *
 */
public class SentenceChunker extends TextChunkerAbstract{

	// later we have to take that from the properties


	
	
	// ========================================================================
	public SentenceChunker(int target) {
		super(target);
	}
	// ========================================================================
	
	
	@Override
	public int perform() {
		// 
		int result=-1;
		
		int p,p1,nw,z,nnum,abslimit ;
		String candidateSnip="" ;
		double np;
		
		text = particledText.getRawText();
		abslimit = text.length();
		
		
		try{
			p1=0;
			p = strgutil.indexOf(text, sentenceDelimChars, p1) ;
			z=0;
			while ((p>0) && (z<abslimit)){
				
				p = strgutil.indexOf(text, sentenceDelimChars, p1) ;
				
				if (p>0){
					if (p>p1){
						
						candidateSnip = candidateSnip + text.substring(p1,p); 
						
						// check the candidate...
						nw = countAlphaWords(candidateSnip) ;
						
						if (nw > minimumLengthAlphaWords){
							
							nnum = strgutil.extractNumsFromString(candidateSnip).size() ; 
							np = (double)nnum/((double)(candidateSnip.length()));
							
							if (np<maximumPortionNums) {
								
								// assimilate
								candidateSnip = "";
								abslimit = text.length()-p;
								z=0;
							}
							
						} // long enough
						
						
						p1=p;
					} // further down than last time ?
					
				}else{
					if (p==0){
						p1++;
					}else{
						// completed, take the rest (if there is any) as the last sentence
						
					}
				}
				
				
			}// ->
			
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		
		return result;
	}
	
	
	private int countAlphaWords(String str) {
		// 
		return 0;
	}


 

}










